(function (global) {
    /**
     * 这里其实还有很多，只参考其它的框架列出一些常用的。
     * @type {Object}
     */
    var attrMap = {
        "class":"className",
        "for":"htmlFor",
        tabindex:"tabIndex",
        readonly:"readOnly",
        maxlength:"maxLength",
        cellspacing:"cellSpacing",
        cellpadding:"cellPadding",
        rowspan:"rowSpan",
        colspan:"colSpan",
        usemap:"useMap",
        frameborder:"frameBorder",
        contenteditable:"contentEditable"
    };
    var ln0 = {
        setAttribute:function (element, name, value) {
            if ('object' != typeof name) {
                name = attrMap[name] || name;
                if (name in element) {
                    //check/selected/href
                    element[name] = value;
                } else {
                    element.setAttribute(element, name, value);
                }
            } else {
                for (var attr in name) {
                    ln.setAttribute(element, attr, name[attr]);
                }
            }
        },
        getAttribute:function (element, name) {
            name = attrMap[name] || name;
            if (name in element) {
                return element[name];
            } else {
                return element.setAttribute(element, name);
            }
        },
        removeAttribute:function (element, name) {
            return element.removeAttribute(name);
        }
    };
    var ln1 = {
        attrHooks:{
        },
        setAttribute:function (element, name, value) {
            if ('object' != typeof name) {
                //plugins start===
                var hook = ln.attrHooks[name];
                if (hook && hook.seter) {
                    hook.seter(element, name, value);
                }
                //plugins end ===
                name = attrMap[name] || name;
                if (name in element) {
                    //check/selected/href
                    element[name] = value;
                } else {
                    element.setAttribute(element, name, value);
                }
            } else {
                for (var attr in name) {
                    ln.setAttribute(element, attr, name[attr]);
                }
            }
        },
        getAttribute:function (element, name) {
            //plugins start===
            var hook = ln.attrHooks[name];
            if (hook && hook.getter) {
                hook.geter(element, name, value);
            }
            //plugins end ===
            name = attrMap[name] || name;
            if (name in element) {
                return element[name];
            } else {
                return element.setAttribute(element, name);
            }
        },
        removeAttribute:function (element, name) {
            //plugins start===
            var hook = ln.attrHooks[name];
            if (hook && hook.remove) {
                return hook.remove(element, name);
            }
            //plugins end ===
            return element.removeAttribute(name);
        }
    };
    /**
     * 1.第2个参数：'string'，如title
     * 正常的情况处理
     * 2.第2个参数：'object'，如{title:'test title!'}
     * 3.第2个参数：'function，即调用这个方法来处理
     */
    var ln2={
        setAttribute:function (element, name, value) {
            switch(typeof name){
                case 'object':
                    for (var attr in name) {
                        ln2.setAttribute(element, attr, name[attr]);
                    }
                    break;
                case 'function':
                    name.call(element);
                    break;
                default :
                    name = attrMap[name] || name;
                    if (name in element) {
                        //check/selected/href
                        element[name] = value;
                    } else {
                        element.setAttribute(element, name, value);
                    }
            }
        },
        getAttribute:function (element, name) {
            if('string' == typeof name){
                name = attrMap[name] || name;
                if (name in element) {
                    return element[name];
                } else {
                    return element.setAttribute(element, name);
                }
            }else{
                //function
                return name.call(element);
            }
        },
        removeAttribute:function (element, name) {
            return element.removeAttribute(name);
        }
    };
    /**
     * 针对上面的hook方案，还有一种办法
     * 第二个参数传入function，针对单独的set/get/remove进行单独的处理
     */
    var ln_w3c = {
        setAttribute:function (element, name, value) {
            if ('object' != typeof name) {
                if (name in element) {
                    element[name] = value;
                } else {
                    element.setAttribute(element, name, value);
                }
            } else {
                for (var attr in name) {
                    ln.setAttribute(element, attr, name[attr]);
                }
            }
        },
        getAttribute:function (element, name) {
            if (name in element) {
                return element[name];
            } else {
                return element.setAttribute(element, name);
            }
        },
        removeAttribute:function (element, name) {
            return element.removeAttribute(name);
        }
    };
    var ln_ie = {
        setAttribute:function (element, name, value) {
            if ('object' != typeof name) {
                name = attrMap[name] || name;
                ln_w3c.setAttribute(element, name, value);
            } else {
                for (var attr in name) {
                    ln_ie.setAttribute(element, attr, name[attr]);
                }
            }
        },
        getAttribute:function (element, name) {
            name = attrMap[name] || name;
            ln_w3c.getAttribute(element, name);
        }
    };
    global.ln2 = ln2;
}(window));